package com.rd.student.jike.class2.lihongming.Solution713;

import sun.font.FontRunIterator;

import java.util.LinkedList;

/**
 * @Auther:Heinrich
 * @Date:2023/7/14-07-14-17:43
 * @Description:com.rd.student.jike.class2.lihongming.Solution713
 * @version:1.0
 */
public class Question8 {
    public static void main(String[] args) {
        LinkedList scoreList = new LinkedList();
        for (int i = 0; i < 20; i++) {
            Score s = new Score();
            s.setId();
            s.setScore();
            scoreList.add(s);
        }
        System.out.println(scoreList);
        System.out.println("最大分");
        System.out.println(ScoreMethod.MaxScore(scoreList));
        System.out.println("最小分");
        System.out.println(ScoreMethod.MinScore(scoreList));
        System.out.println("-------------------------------------");
        System.out.println(ScoreMethod.upSixty(scoreList));
        System.out.println("-------------------------------------");
        System.out.println(ScoreMethod.downSixty(scoreList));
        System.out.println("平均值");
        System.out.println(ScoreMethod.averageScore(scoreList));

    }


}

class Score {
    private static Integer PARSE = 1;
    int id;
    int Score;

    @Override
    public String toString() {
        return
                "id=" + id +
                ", Score=" + Score +
                '\n';
    }

    public Score(int id, int score) {
        this.id = id;
        Score = score;
    }

    public Score() {
    }

    public void setId() {
        this.id = PARSE++;
    }

    public int getScore() {
        return Score;
    }

    public void setScore() {
        Score = (int) (Math.random() * 101);
    }
}

class ScoreMethod {
    public static Score MaxScore(LinkedList<Score> list) {
        Score MaxSc = new Score(0, 0);
        for (Score s : list) {
            if (MaxSc.Score < s.Score) {
                MaxSc = s;
            }
        }
        return MaxSc;
    }

    public static Score MinScore(LinkedList<Score> list) {
        Score MinSc = new Score(0, Integer.MAX_VALUE);
        for (Score s : list) {
            if (MinSc.Score > s.Score) {
                MinSc = s;
            }
        }
        return MinSc;
    }

    public static LinkedList<Score> upSixty(LinkedList<Score> list) {
        LinkedList scoreUp = new LinkedList();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).Score >= 60) {
                scoreUp.add(list.get(i));
            }
        }
        return scoreUp;
    }

    public static LinkedList<Score> downSixty(LinkedList<Score> list) {
        LinkedList scoreDown = new LinkedList();
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i).Score < 60) {
                scoreDown.add(list.get(i));
            }
        }
        return scoreDown;
    }
    public static double averageScore(LinkedList<Score> scores){
        double average = 0.0;
        for(Score s:scores){
            average+=s.Score;
        }
        return average/(double) (scores.size());
    }
}